package com.uniapp.java.uniappjava.utils;

import lombok.Builder;
import lombok.Data;

/**
 * @author lsy_server
 */
@Data
@Builder
public class Result<T, M> {
    private Integer status;
    private T data;
    private M errorMessage;

    public static <T, M> Result ok(T data, M errorMessage) {
        return Result.builder().data(data).status(ResponseStatus.SUCCESS).errorMessage(errorMessage).build();
    }

    public static <T> Result ok(T data) {
        return ok(data, null);
    }

    public static Result ok() {
        return ok(null);
    }


    public static <T, M> Result error(Integer status, T data, M errorMessage) {
        return Result.builder().data(data).status(status).errorMessage(errorMessage).build();
    }

    public static <T, M> Result error(T data, M errorMessage) {
        return error(ResponseStatus.ERROR, data, errorMessage);
    }

    public static <T> Result error(Integer status, T data) {
        return error(status, data, null);
    }

    public static <T> Result error() {
        return error(ResponseStatus.ERROR, null);
    }
}
